package com.jk1.bianligou.blg.config;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * @author WHH
 */
@Data
@ConfigurationProperties(prefix = "alipay")
@Configuration
@Slf4j
public class AlipayConfig {
    /**
     * APPID
     */
    private String appId;

    /**
     * 商户私钥, 即PKCS8格式RSA2私钥
     */
    private String privateKey;

    /**
     * 公钥
     */
    private String publicKey;
    /**
     * 支付宝公钥
     */
    private String alipayKey;

    /**
     * 服务器异步通知页面路径,需http://格式的完整路径
     * 踩坑:不能加?type=abc这类自定义参数
     */
    private String notifyUrl;

    /**
     * 页面跳转同步通知页面路径,需http://格式的完整路径
     * 踩坑:不能加?type=abc这类自定义参数
     */
    private String returnUrl;

    /**
     * 签名方式
     */
    private String signType;

    /**
     * 字符编码格式
     */
    private String charset = "UTF-8";

    /**
     * 支付宝网关
     */
    private String gatewayUrl;

    /**
     * 日志打印地址
     */
    private String logPath = "/log";

    @PostConstruct
    public void init() {
        // 设置参数（全局只需设置一次）
        Config config = new Config();
        config.protocol = "https";
        config.gatewayHost = "openapi.alipaydev.com";
        config.signType = this.signType;
        config.appId = this.appId;
        config.merchantPrivateKey = this.privateKey;
        config.alipayPublicKey = this.publicKey;
        config.notifyUrl = this.notifyUrl;
        Factory.setOptions(config);
        log.info("=======支付宝SDK初始化成功=======");
    }


}